<?php
require_once MODEL_DIR.'/ProjectModel.php';
$oProjectInstance = new ProjectModel();

if(isset($_GET['option'])){
	if(isset($_POST['submit'], $_POST['idProject'])){
		switch($_GET['option']){
			case 'check':
				if($_POST['statusProject'] == 2){
					$oProjectInstance->updateDate($_POST['idProject'], 'dateEndProject');
				}elseif($_POST['statusProject'] == 3){
					$aiassProjectsList = $oProjectInstance->getProjects('WHERE idProject = '.$_POST['idProject']);
					$asmProject = $aiassProjectsList[0];
					if($asmProject['statusProject'] != 3){
						$oProjectInstance->updateDate($_POST['idProject'], 'dateBeginProject');
					}
				}
				ProjectModel::editProject($_POST);
				header('Location: index.php?page=adminIndex&mod=project&action=edit');
			break;
			case 'edit':
				$aiassProjectsList = $oProjectInstance->getProjects('WHERE idProject = '.$_POST['idProject']);
				$asmProject = $aiassProjectsList[0];
				require_once VIEW_DIR.'/formProjectEdit.php';
			break;
			default:
				header('Location: index.php?page=adminIndex&mod=project&action=edit');
			break;
		}
	}
}else{
	$aiassProjectsList = $oProjectInstance->getProjects();
	require_once VIEW_DIR.'/formProjectSelectEdit.php';
}
